home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / Alpha.5.05.cpt / Help / Tickle < prev    next >
Text File  |  1992-08-31  |  35KB  |  816 lines

  1.  
  2.                     tickle
  3.            Assembled and Written By
  4.                   Tim Endres
  5.  
  6.                 April 2, 1992
  7.                 Release 3.1v4
  8.  
  9.          Internet:         time@ice.com
  10.          UUCP:          heifetz!tbomb!time
  11.          AppleLink:   time@ice.com@INTERNET#
  12.          CompuServe:  >INTERNET:time@ice.com
  13.  
  14.  
  15. This software is the result of a network programming community propelled 
  16. by software sharing, allowing work to be built upon others' work 
  17. eliminating redundancy and allowing continual incremental 
  18. enhancement.
  19.  
  20. Please give tickle to anyone you wish, but please give them the entire 
  21. package so that they have the documentation and references.
  22.  
  23. If you have any questions, suggestions, or just have some compelling need 
  24. to send email, please address it to tickle@ice.com.
  25.  
  26.  
  27. *** What is Tickle? ***
  28.  
  29. Tickle is a glom of items that were assembled over a long period of time. 
  30. Some was my own insanity and others came from the net. Finally, the nice 
  31. little tcl language came up at USENIX, several people moaned about 
  32. wanting it on the Mac, and it seemed reasonable.
  33.  
  34. You will find that tickle is an invaluable tool in dealing with the various 
  35. data formats flying around on USENET as well as for various Macintosh 
  36. file formats. You will find BinHex, MacBinary, Apple Single/Double, Tar, 
  37. Compress, uuencode, and several TEXT file conversion utilities.
  38.  
  39. The added bonus of tcl allows for the automation of some of your tasks, as 
  40. the tcl language has been extended to support the file utilities of the 
  41. application, as well as allowing for further extensions by the user via 
  42. external commands ala HyperCard XCMDs. Support of HyperCard XCMDs 
  43. is being investigated for a future release.
  44.  
  45.  
  46. *** What is TCL? ***
  47.  
  48. You should refer to the various included man pages and papers submitted 
  49. to USENIX for details about tcl. Briefly, tcl is a simple string based 
  50. scripting language designed to be included in standard applications. It will 
  51. allow you to perform many tasks that are otherwise very labor intensive.
  52.  
  53. TCL was created by a small set of very bright engineers, namely, John 
  54. Ousterhout and his graduate students. The Unix extensions were invented 
  55. and implemented by Karl Lehenbauer, Mark Diekhans and Peter da Silva 
  56. with help from Jordan Henderson. TCL was simply ported into tickle by 
  57. Tim Endres. Refer to the included documentation for further details.
  58.  
  59. Tickle comes with the libraries for the tcl interpreter included in tickle, so 
  60. that you may incorporate them into your work (assuming you have MPW). 
  61. Otherwise, you may retrieve the sources for the tcl interpreter from ICE. 
  62. The changes are significant, but based on release 4.0. Hopefully, we can 
  63. somehow get these modifications put into the general tcl release, but in the 
  64. meantime, people can use at least tcl. The release seems very stable.
  65.  
  66. To open a tcl script window, hold down the Shift key when you click on the 
  67. File menu, or when you use Cmd-N or Cmd-O. In script windows you can 
  68. execute any valid tcl code by selecting the text and pressing the Enter key (or 
  69. Apple-Return, or the yin-yang icon next to the horizontal scroll bar).
  70.  
  71. *** TCL Extensions ***
  72.  
  73. To make the tcl interpreter even more versatile, tickle gives you a text 
  74. window in which you can type tcl scripts, and execute tcl code by simply 
  75. selecting text and pressing the Enter key!! This will provide you with a very 
  76. powerful environment in which to experiment with tcl. You will find the 
  77. interface to be very much like MPW.
  78.  
  79. Further, the tcl language has been extended to allow you to write external 
  80. code resources (type 'XTCL') that are very similar in mechanism to 
  81. HyperCard's XCMDs. This will allow you to extend the tcl language 
  82. without dealing with the tcl sources, or rebuilding the tickle application.
  83.  
  84.  
  85. *** Tickle TCL Interpreters ***
  86.  
  87. Anytime that you open a Text Window in tickle, you have instantiated a tcl 
  88. interpreter. You may treat the window as a text editor, or as a tcl shell. It 
  89. becomes a shell when you press the Enter key to execute the current line or 
  90. selection.
  91.  
  92. Each text window gets its own instantiation of a tcl interpreter. This means 
  93. that a command defined in one text window will not be available in another 
  94. text window's interpreter. This also means that a procedure may have two 
  95. different meanings in two different windows, without a conflict.
  96.  
  97. However, there are times when tickle needs to have a tcl interpreter 
  98. available, even if there is no text window open. For instance, if a DoScript 
  99. Apple Event comes into tickle, it will need an interpreter to execute the 
  100. script. To handle these situations, tickle creates a global interpreter. This 
  101. interpreter is created at startup of tickle, and lives until tickle is quit. The 
  102. global interpreter is where Apple Event scripts are executed, and where 
  103. Finder dropped tcl scripts are executed, and where the tickle CRON 
  104. expression is executed.
  105.  
  106. You may cause a text window to use the global interpreter, instead of a 
  107. private interpreter, by holding down the Shift key when opening the text 
  108. window. Text windows using the global interpreter will have the word 
  109. Global displayed in their lower left corner, instead of Local.
  110.  
  111. Also note that the script •tclinit will be executed within the context of the 
  112. global interpreter at tickle startup time. This provides an opportunity to 
  113. establish the global interpreter for commonly used extensions and for 
  114. CRON type tasks.
  115. Specific TCL Extensions
  116.  
  117. The following commands have been added to the standard tcl command set 
  118. for the tickle application. The commands are mostly Macintosh specific. 
  119. Further, commands are provided to allow you to utilize the file utilities built 
  120. into tickle.
  121.  
  122. alertnote message_string
  123.   This command will display message_string in a standard Macintosh alert box.
  124.  
  125. cd directory
  126.   This command will set the current working directory to directory. The directory 
  127.   argument may or may not end with a colon. The working directory is the directory 
  128.   in which file names that contain no colons (folders) will be located with file related 
  129.   commands.
  130.  
  131. pwd
  132.   This command will return the current working directory.
  133.  
  134. get_directory
  135.   This command will display a standard Macintosh file dialog and request the user 
  136.   select a folder. The command will return the selected folder's full path name, or an 
  137.   empty string if the Cancel button was selected.
  138.  
  139. getenv varname
  140.   This command will return the value of the environment variable varname. 
  141.   Environment variables are initialized by reading the file •tclenv. The environment 
  142.   file has the format varname=value as in the following example:
  143.  
  144.     TERM=vt100
  145.     TCLINIT=::tcl:TclInit.tcl
  146.     TCLDEFAULT=
  147.     TEST=TEST
  148.     TCLPATH=::tcl:tclsh:tclsrc
  149.  
  150. putenv varname value
  151.   This command will set the environment variable varname to value.
  152.  
  153. cp fromName toName [force]
  154.   This command will copy the file fromName and name the new file toName. If 
  155.   toName includes a path name that is different from the path in fromName, the copy 
  156.   will be made in a new directory (specified by toName). The copy can be made 
  157.   across volume (disk drives). The force option indicates that the copy should 
  158.   overwrite any existing file with the same name as toName. This command copies 
  159.   both data forks, and the Finder information.
  160.  
  161. mv fromName toName [force]
  162.   This command will move the file fromName to toName. If toName includes a path 
  163.   name that is different from the path in fromName, the file will be moved into a new 
  164.   directory (specified by toName). The move can not be made across volume (disk 
  165.   drives). The force option indicates that the move should overwrite any existing file 
  166.   with the same name as toName.
  167.  
  168. rm fileName
  169.   This command will delete the file fileName.
  170.  
  171. xtclcmd [-f filename] cmdname argument_list...
  172.   This command will load the external command cmdname and pass it the argument 
  173.   list [ cmdname argument_list... ]. External command are code resources of type 
  174.   XTCL. They may be located in the resource fork of the tickle application, or they 
  175.   may be located in a file named XTCL File in the same directory as the tickle 
  176.   application. If the optional -f filename is included, the external command will first 
  177.   be loaded from filename before the other two files.
  178.   See the appendix for a detailed description of the external tcl command interface. 
  179.   See the accompanying sources for an example of writing an XTCL.
  180.  
  181. askyesno prompt
  182.   This command will display a Macintosh alert box with promptdisplayed with the 
  183.   push buttons Yes, No, Cancel.. The command will return the title of the button 
  184.   selected by the user.
  185.  
  186. getline prompt default
  187.   This command will display a Macintosh alert box with promptdisplayed, a text edit 
  188.   field with default initially in the field, and with the push buttons OK, Cancel.. The 
  189.   command will return the text entered into the text edit field by the user, or an empty 
  190.   string if the user selected the Cancel button.
  191.  
  192. getfile prompt
  193.   This command will display an SFGetFile() and return the full path name of the 
  194.   selected file, or an empty string if CANCEL button was selected.
  195.  
  196. putfile prompt original
  197.   This command will display an SFPutFile() and return the full path name of the 
  198.   selected file, or an empty string if CANCEL button was selected. Original is the 
  199.   default name displayed for the user.
  200.  
  201. getfinfo fileName
  202.   This command will display the standard Macintosh file information in the form:
  203.   "'aeQL' 'QUIL' lvbsIdm 02/17/92 23:57:12 02/19/92 22:43:36 0,156 219 0".
  204.   The fields are the fdCreator, fdType, fdFlags, flCreationDate, flCreationtime, 
  205.   flModDate, flModTime, fdLocation.H,V, dataForlLength, rsrcForkLength, 
  206.   respectively. The fdFlags field uses characters to represent bits:
  207.     l/L    not locaked/Locked
  208.     v/V    visible/notVisible
  209.     b/B    not bundled/Bundled
  210.     s/S    not system/System
  211.     i/I    not initialized/Initialized
  212.     d/D    not desktop/Desktop
  213.     m/M    not sharable/sharable
  214.  
  215. setfinfo fileName [-a flags]
  216.             [-c fdCreator] [-t fdTypes]
  217.   This command will set the standard Macintosh file information. The flags setting 
  218.   must be of the same format as displayed by the getfinfo flag.
  219.  
  220. feedback string
  221.   This command will display the string in the feedback window, as well as log the 
  222.   string if logging is turned on.
  223.  
  224. ctime time
  225.   This command will return a UNIX time string of the format "Wed Feb 19 
  226.   22:43:36 1992". The parameter time is in Macintosh seconds, and would be the 
  227.   result of a now or file mtime command or the like.
  228.  
  229. now
  230.   Returns the current time as Macintosh seconds. This is the number of seconds that 
  231.   have elapsed since Midnight Jan 1, 1904. Appropriate for input to ctime.
  232.  
  233. ticks
  234.   Returns the current TickCount. Ticks are 60ths of a seconds. TickCount is the 
  235.   number of ticks since the Macintosh was started. The command:
  236.         puts stdout [expr "[ticks] / 60"]
  237.   will print the number of seconds since the Macintosh was booted.
  238.  
  239. mtime time ?long/short/abbrev?
  240.   Returns a date and time string using the Macintosh International Utilities. The 
  241.   long/short/abbrev specification corresponds to the date. These are the following 
  242.   formats:
  243.     short        3/16/92 9:20:46 PM
  244.     abbrev    Mon, Mar 16, 1992 9:20:49 PM
  245.     long        Monday, March 16, 1992 9:20:43 PM
  246.  
  247. listpick -p prompt list
  248.   This command will display a dialog with the list displayed in a List Manager list. If 
  249.   the user presses the Cancel button, an empty string is returned. If the user selects 
  250.   the Open button, or double clicks an item in the list, that item will be returned.
  251.  
  252. glob
  253.  
  254. The original glob provided by the UNIX version of tcl was not quite adequate for 
  255. the more complex Macintosh file system. Issues such as invisible file handling, 
  256. Finder type and creator filtering, and space handling in file names. Release 6 of tcl 
  257. has dealt with the original problem with spaces in filenames, but the following 
  258. options are provided to deal with additional Macintosh issues.
  259.  
  260. Anyhow, the new glob now takes several options. They are:
  261.     -i    This option causes glob to list invisible files also.
  262.     -t TYPE    This option causes glob to only list file with the 
  263.         indicated Finder file typeTYPE. This option may be 
  264.         used with the -c option.
  265.     -c CRTR    This option causes glob to only list file with the 
  266.         indicated Finder file creatorCRTR. This option may 
  267.         be used with the -t option.
  268.         Also note that the original glob would skip dot files
  269.         (i.e., file names the begin with a period) 
  270.         in the listing, unless the pattern began with a period.
  271.         Tickle extends this concept one step further on the
  272.         Macintosh, and skips spot files (i.e., file names that 
  273.         begin with '•'), unless the pattern starts with a spot.
  274.  
  275. yield_mac ?ticks? *** NOT YET INCORPORATED INTO ALPHA ***
  276.   This will cause tcl to call WaitNextEvent, allowing other processes to run during 
  277.   CPU intensive tcl scripts, as well as allowing the user to switch application while a 
  278.   particularly long script is executing. The ticks argument determines the sleep_time 
  279.   ticks passed to WaitNextEvent() and as such determine the amount of sharing of the 
  280.   CPU that will be accomplished. Larger ticks values will slow down the tcl script 
  281.   allowing other programs more of the CPU. Smaller ticks values will speed up the 
  282.   tcl script at the expense other programs getting less of the CPU.
  283.  
  284. start_progress title start end pos msgexprc *** NOT YET INCORPORATED INTO ALPHA ***
  285.   This will display a small window in which a sliding bar progress indicator will be 
  286.   displayed. The title will be the window title. Startand end are the end points of the 
  287.   progress indicator, and pos is the initial position of the indicator and must be 
  288.   between start and end. Msgexpr is a tickle expression that will be evaluated each 
  289.   time the position is updated by the update_progress function. The result of this 
  290.   expression will be displayed in the progress window as the progress message, and 
  291.   thus will most likely be the format command.
  292.  
  293. update_progress position *** NOT YET INCORPORATED INTO ALPHA ***
  294.   This will update the progress indicator to show progress to position.
  295.  
  296. stop_progress *** NOT YET INCORPORATED INTO ALPHA ***
  297.   This will close the progress indicator window.
  298.  
  299. logging on|off ?filename? *** NOT YET INCORPORATED INTO ALPHA ***
  300.   This will turn the tickle logging on or off. If filename is provided with the on 
  301.   option, then the log file will be changed over to using the file named.
  302.  
  303. *** MORE EXTENSIONS ***
  304.  
  305. Many extensions to tickle were provided by Karl Lehenbauer and Mark Diekhans. 
  306. The most beneficial of those for tickle were included. These included math and 
  307. string functions, as well as a neat new loop command. The man pages are included 
  308. for some of these commands, but here is a brief summary.
  309. There are math functions:
  310.     acos    asin    atan    cos    sin    tan    cosh    sinh    tanh
  311.     exp    log    log10    sqrt    fabs    floor    ceil    fmod    pow
  312. The trig functions work with radians.
  313. The function pi will simply return the constant.
  314. The functions max and min will work on lists of floating point numbers.
  315. The function random  limit will return a random number between + and - limit.
  316. The function random seed [seedval] will set the seed for the random function to 
  317. seedval, or to the current time if seedval is not provided.
  318.  
  319. The function loop varname start end increment expr will increment the variable 
  320. varname from start to end by increment while executing expr for each increment.
  321.  
  322. *** Apple Event TCL Extensions *** NOT YET INCORPORATED INTO ALPHA ***
  323.  
  324. This implementation of tickle has extensive support for Apple Events. This 
  325. includes both support of the standard suite of events, as well as support for 
  326. script events, installing your own coercion and event handling routines, as 
  327. well as the ability to send Apple Events to other processes.
  328.  
  329. Tickle supports the 'misc' 'dosc' Apple Event, otherwise known as 
  330. DoScript.  Further, tickle supports both the typeChar and typeAlias forms of 
  331. input to the DoScript event. For the typeChar form, the text will be 
  332. considered a script and executed. For the typeAlias form, the file 
  333. represented by the alias will be executed. In either case, the result will be 
  334. returned via the reply as typeChar. The script will always be executed in 
  335. the context of the global interpreter.
  336.  
  337. Tickle also allows you to install Apple Event handlers via the aeload 
  338. command described below. This will install stand alone code modules to 
  339. handle Apple Events. The refCon to these handlers will point to a struct 
  340. that gives you the interpreter pointer to the global tcl interpreter, as well as 
  341. a procedure to make it easy for you to make calls back to the tcl interpreter 
  342. without linking in the tcl libraries in your handler. The aeload command 
  343. will also load coercion handlers. For more details on writing an Apple 
  344. Event handler or a coercion procedure, see the example sources included.
  345.  
  346. The loaded code resources are simply code resources with special names 
  347. that indicate their behavior. The first 4 characters (quartet ) of the name 
  348. determine the code type:
  349.  
  350. AEVT    Apple Event Handler.
  351. CSPT    Pointer based coercion handler.
  352. CSDS    AEDesc based coercion handler.
  353.  
  354. For AEVT resources, the second quartet of characters in the name 
  355. represent the event class and the third quartet of characters in the name 
  356. represent the event ID.
  357.  
  358. For CSPT and CSDS resources, the second quartet of characters in the 
  359. name represent the descriptor type of the incoming data (i.e., the from type) 
  360. and the third quartet of characters in the name represent the descriptor 
  361. type of the desired coercion (i.e., the to type).
  362.  
  363. Several commands have been added to the tcl language to facilitate the 
  364. sending of Apple Events to other hosts. They are itemized here:
  365.  
  366. aeopen name [ApplSig | port_name location_name]
  367.  
  368. This command creates a named connection with which you can send Apple Events 
  369. to other processes. If the ApplSig parameter is present, then the target will be the 
  370. local application with the specified four character signature.
  371. If the port_name location_name parameters are given, they will define a process via 
  372. the PPCPortRec and LocationNameRec structures. The port_name paramater 
  373. should be in the form "name,type" and location_name should be in the form 
  374. object:type@zone. For instance, "tclEngine,tcl engine" "Joe's 
  375. Macintosh:PPCToolbox@myzone".
  376. If no parameters are present, the command will display the PPCBrowser dialog 
  377. allowing you to select a process. Once this command is successfully executed, the 
  378. name may be used in any of the Apple Event commands listed below to identify the 
  379. targret of the Apple Event. There are a maximum of eight (8) targets that may be 
  380. open simultaneously.
  381.  
  382.  
  383. aeclose name
  384.  
  385. This command will close the named Apple Event target opened by aeopen.
  386.  
  387.  
  388. aesend name [-t ticks] [-w] [-i] [-o] [-l] [-x]
  389.         class event data
  390.  
  391. This command is used to send an Apple Event to the named target, name, 
  392. previously opened by aeopen. Class and event are the corresponding four character 
  393. types that determine the class and event id of the Apple Event. The data field 
  394. contains the desired contents of the Apple Event.
  395. The -t option allows the specification of the send timeout in ticks. The default is 120 
  396. or 2 seconds. The -w option uses the kAEWaitReply option, where kAENoReply is 
  397. the default. The -i option uses the kCanInteract option, where kAENeverInteract is 
  398. the default. The -o option allows you to select the standard output of the reply data. 
  399. This is only useful when talking with another tickle, since the standard output 
  400. paramater type is only defined by tickle. The -l option specifies that you want the 
  401. output in long format, with the returned data type (4 characters) first, then the data. 
  402. The -x option is used to get the output as hex data instead of text data. Regardless 
  403. of the data output format or options, the output will always be bracketed by curly 
  404. braces to avoid problems with spaces in the output.
  405. The data field consists of pairs of parameters, the first being a flag and the second 
  406. data. The flag either begins with '+' or '-'. A '-' indicates that the two following 
  407. quartets of characters are the data key and type of the data that follows. For 
  408. example:
  409.     -----TEXT "This is a string."
  410. would create an Apple Event that contained a Direct Parameter (----) of type 
  411. 'TEXT'. This is a perfectly good type for sending scripts, as in:
  412.     aesend NAME misc dosc -----TEXT {print "Hello World!"}
  413.  
  414. The other form of data specification is the '+' form. This form uses the AEBuild 
  415. tool from Apple. This is described in the AEBuild document. Briefly, AEBuild is a 
  416. tool that allows you to give a detailed Apple Event description with a flexible 
  417. syntax. Thus, the above example might be written as:
  418.     aesend NAME misc dosc +---- {“print "Hello World!"”}
  419.  
  420. The AEBuild syntax allows for more complex descriptions, most importantly lists, 
  421. which are required for simple things like 'aevt' 'odoc'.
  422. AEBuild has one major shortcoming. When it performs coercion, it only calls the 
  423. coercion handler if the coercion is numeric. For all other coercions, AEBuild simply 
  424. modifies the descriptorType field of the AEDesc structure. Because of this, you will 
  425. have to use the ability to install coercion handlers to produce HEX data, which you 
  426. can place in the AEBuild specification with the aecoerce command. Since the HEX 
  427. data is native,  the only coercion requirement is the setting of the descriptorType 
  428. field.
  429. If you followed the above discussion, then you will recognize the following 
  430. command as a simple request to open a document. You will also note that it 
  431. depends upon an external coercion handler named PROC_TEXTalis, which 
  432. converts a full path name into an alias.
  433.     aesend TOOL aevt odoc +---- [ concat
  434.         {[ alis(«} [ aecoerce TEXT "Quill.txt" -x alis ] {») ]}
  435.         ]
  436.  
  437.  
  438. aeload filename
  439.  
  440. This command will load all coercion and Apple Event handlers contained in 
  441. filename.
  442.  
  443.  
  444. aecoerce fromType [-x] data [-x] toType
  445.  
  446. This command will call the appropriate coercion handler to coerce data from 
  447. fromType into toType.
  448. The data is considered to be text, unless the optional -x is present immediately 
  449. before the data parameter, in which case it is considered to be hex data. The data 
  450. will be read into the dataHandle of an AEDesc structure, then the descriptorType 
  451. field set to fromType, and the AEDesc structure passed to AECoerceDesc() to be 
  452. coerced into toType.
  453. The resulting data will be returned as text data (which is problematic if it contains 
  454. zeros in the data), unless the optional -x is present immediately before thetoType 
  455. parameter, in which case the data will be returned as hex data.
  456.  
  457.  
  458. aelist
  459.  
  460. This command will list all open targets that were obtained via aeopen.
  461.  
  462.  
  463. aetargets object type zone
  464.  
  465. This command will list all available targets according to the specified parameters. 
  466. The object parameter is the name of a Macintosh in zone. The type field should 
  467. usually be set to PPCToolbox.
  468.  
  469.  
  470. aeinteract
  471.  
  472. This command is used when you are running a script via Apple Event, and need 
  473. user interaction. If you do not call this, user interaction may behave improperly.
  474.  
  475.  
  476. *** APPENDIX  -  A ***
  477.  
  478. *NOTE*
  479. =============================================================================
  480. I have not done extensive testing of Alpha with XTCLs. However, all those 
  481. that I did try worked correctly. For more information on XTCLs, as well as 
  482. sample code, download the file XTCL.cpt.bin from the Alpha archive site, 
  483. cs.rice.edu in the directory public/Alpha. Additionally, this information 
  484. can be obtained with the rest of the tickle distribution from ftp.msen.com 
  485. in the directory "pub/vendor/ice". 
  486.                                                 -- pete
  487. =============================================================================
  488.  
  489. The tcl external command interface is similar to the HyperCard external 
  490. command interface. Your code is a stand alone module that exists as a 
  491. resource in the common XTCL File or in a file by itself.
  492.  
  493. The advantage of having your XTCL in a separate file is the ability to have 
  494. access to your own set of resources that are always carried around with the 
  495. XTCL. The disadvantage is the cost of opening and close the XTCL's file 
  496. every time it is executed. A future release of tickle will cache the current 
  497. open XTCL resource, as well as the open resource file, making repeated 
  498. calls to the XTCL very fast.
  499.  
  500. When tickle is asked to execute the external command, it loads the resource 
  501. from the (1) application resource fork, (2) the XTCL File resource fork, or (3) 
  502. the resource fork of the optional file parameter. The resource is locked 
  503. down in memory, and called as a C function. The external command's C 
  504. code should begin as:
  505.  
  506. void
  507. XTCLEntry(argc, argv, xpb)
  508. int            argc;
  509. char            **argv;
  510. XTCLParmBlk        *xpb;
  511.  
  512. The parameters are similar to what you would expect any C type program 
  513. to take, except for the xpb parameter block. This parameter block is your 
  514. link back into tickle. Here is the structure:
  515.  
  516. typedef struct {
  517.  ->    long    version;
  518. <->    long    result;
  519. <->    Handle    resultH;
  520.  ->    short    cmdRefNum;
  521.  ->    Handle    cmdHandle;
  522.  ->    Tcl_Interp    *interp;
  523.  ->    int    (*eval)();
  524.  ->    ModalFilterProcPtr    modalproc;
  525.  -    long    reserved;
  526.     } XTCLParmBlk, *XTCLPBPtr;
  527.  
  528. The version field is passed in to indicate to the command what level of 
  529. functionality the tcl callback function supports, as well as indicate the 
  530. version of the parameter block data structure. The current version number 
  531. of defined by XTCL_CB_VERSION in the header file XTCL.h and is currently 
  532. 0x00010001.
  533.  
  534. The result field is returned by the external command and is to be one of 
  535. the predefined constants in XTCL.h. The resultH field contains a handle 
  536. that is allocated by tickle, with a length of zero, and passed to the external 
  537. command to contain the results of the command. The command will resize 
  538. the handle to hold its result, and copy the results into the handle's memory 
  539. before returning. The external command should never dispose of the 
  540. handle passed in resultH.
  541.  
  542. The cmdRefNum field is the file system reference number of the file 
  543. containing the XTCL command. Remember, this reference number may be 
  544. the application's reference number or the number of the XTCL File, if the 
  545. command was found in either of these locations. The external command 
  546. must never close this file.
  547.  
  548. The cmdHandle field is the handle to the code resource that contains the 
  549. external command itself. It will be locked. Do not unlock, move, modify, or 
  550. otherwise mutilate this memory!!!! Consider the handle and data READ 
  551. ONLY.
  552.  
  553. The interp field is a tcl interpreter pointer to the interpreter that called the 
  554. external command. 
  555.  
  556. The eval field is a C procedure pointer to the callback routine to evaluate a 
  557. tcl statement. It is equivalent to using the eval tcl command. The callback is 
  558. used as follows:
  559.  
  560.    result = (* xpb->eval)(xpb, sHandle, rHandle, stdoutHandle);
  561.  
  562. Where:
  563. xpb is the parameter block pointer passed to the external command.
  564. sHandle is a handle containing a null terminated string to be evaluated by the tcl 
  565. interpreter.
  566. rHandle is a handle for the result of the command. It may be zero length, but if it is 
  567. not the results will be placed after the data already in the handle (as determined by 
  568. GetHandleSize). The result will not be null terminated, thus, GetHandleSize must 
  569. be used to determine the length of the result.
  570. stdoutHandle is a handle for the standard output of the command. This is the 
  571. output generated by the print command and error reporting. It may be zero length, 
  572. but if it is not the results will be placed after the data already in the handle (as 
  573. determined by GetHandleSize). The results will not be null terminated, thus, 
  574. GetHandleSize must be used to determine the length of the result. This field may be 
  575. NULL.
  576.  
  577. The modalproc field is a procedure pointer to use in the 
  578. ModalFilterProcPointer field of ModalDialog and the like. 
  579.  
  580. The reserved field is reserved. 
  581.  
  582. An external command in MPW C should look like:
  583.  
  584. #include "xtcl.h"
  585.  
  586. void
  587. XTCLEntry(argc, argv, xpb)
  588. int            argc;
  589. char        **argv;
  590. XTCLParmBlk    *xpb;
  591. {
  592. char    *ptr, state;
  593. int        i, length, slen;
  594.  
  595.     xpb->result = TCL_OK;
  596.     
  597.     length = GetHandleSize(xpb->resultH);
  598.     
  599.     for (i=1; i < argc; i++)
  600.         slen += strlen(argv[i]) + 1;
  601.  
  602.     SetHandleSize(xpb->resultH, slen+1);
  603.     
  604.     state = HGetState(xpb->resultH);
  605.     HLock(xpb->resultH);
  606.     
  607.     for (ptr=*xpb->resultH, i=1; i < argc; i++) {
  608.         strcat(ptr, argv[i]);
  609.         strcat(ptr, " ");
  610.         ptr += strlen(ptr);
  611.         }
  612.  
  613.     HSetState(xpb->resultH, state);
  614.     }
  615.  
  616. And would be linked together with:
  617.  
  618. XTCL_echo ƒ                ∂
  619.         XTCL_echo.c.o
  620.     Echo '#' Linking XTCL_echo
  621.     Link -t "XTCL" -c "MPS "        ∂
  622.         -rt "XTCL=2020"        ∂
  623.         -sg "echo"            ∂
  624.         -m XTCLEntry            ∂
  625.         -o XTCL_echo            ∂
  626.         XTCL_echo.c.o            ∂
  627.         {CLibraries}StdCLib.o    ∂
  628.         {Libraries}Interface.o
  629.  
  630. NOTE: The -sg "echo" option in the Link command will determined the 
  631. name of the code resource that is produced, and thus the name of the 
  632. external command. The -rt "XTCL=2020" option in the Link command 
  633. determines the resource type of the code generated, and its resource id. 
  634. The resource type must be XTCL, and the resource ID should try to be 
  635. unique, but is not critical.
  636.  
  637. Also remember that stand alone C code must not use global variables, and 
  638. must use the -b option when calling the C compiler to use string constants.
  639.  
  640. Finally, the following code fragment is an example of an XTCL that simply 
  641. calls the eval callback routine with its first argument to be evaluated.
  642.  
  643. #include "xtcl.h"
  644.  
  645. void
  646. XTCLEntry(argc, argv, xpb)
  647. int        argc;
  648. char        **argv;
  649. XTCLParmBlk    *xpb;
  650.     {
  651.     long        length;
  652.     int        result;
  653.     Handle        rHandle, sHandle;
  654.     char        *script = argv[1];
  655.  
  656.     xpb->result = TCL_OK;
  657.     
  658.     length = strlen(script);
  659.     sHandle = NewHandle(length+1);
  660.     rHandle = NewHandle(0);
  661.     
  662.     if (sHandle != NULL && rHandle != NULL)
  663.         {
  664.         strcpy(*sHandle, script);
  665.         
  666.         result = (* xpb->eval)(xpb, sHandle, rHandle, NULL);
  667.         
  668.         length = GetHandleSize(rHandle);
  669.         SetHandleSize(xpb->resultH, length + 1);
  670.         if (MemError() == noErr) {
  671.             memcpy(*xpb->resultH, *rHandle, GetHandleSize(rHandle));
  672.             * (*xpb->resultH + length) = '\0';
  673.             }
  674.         else
  675.             result = TCL_ERROR;
  676.         
  677.         xpb->result = result;
  678.         }
  679.     
  680.     if (sHandle != NULL)
  681.         DisposHandle(sHandle);
  682.     if (rHandle != NULL)
  683.         DisposHandle(rHandle);
  684.     }
  685.  
  686. NOTE: Pascal programmers will need to link with the Pascal glue code to 
  687. work. The glue code provides a C entry that will call your Pascal routine for 
  688. the XTCL. It also provides glue to callback the interpreter for evaluation. 
  689. Please see the example sources and makefile for further details.
  690.  
  691.  
  692. *** APPENDIX  -  B ***
  693.  
  694. The tcl external procedure interface is identical to the interfaces used by the 
  695. Apple Event loaders provided with the System Seven Developer CD. These 
  696. procedure definitions allow you to define Apple Event Coercion procedures 
  697. and Apple Event Handler procedures to be loaded by tickle for use with 
  698. tickle's tcl.
  699.  
  700. The current release of tickle includes two such procedures: 
  701. PROC_AEVTtcl1evel and PROC_CSPTTEXTalis. PROC_AEVTtcl1evel  is 
  702. an example of an Apple Event Handler that handles the event class tcl1 and 
  703. event type eval. PROC_CSPTTEXTalis is an Apple Event Coercion handler 
  704. that coerces a full path name passed as data type TEXT into an Alias of type 
  705. alis.
  706.  
  707. To load the external procedure definitions, you must use the aeload 
  708. command. The type of handler and its input and output data types are 
  709. determined by the name of the code resource. The first four characters are 
  710. the handler type:
  711.  
  712.     AEVT    - Apple Event Handler.
  713.     CSPT    - Data Pointer based Coercion Routine.
  714.     CSDS    - Data Descriptor based Coercion Routine.
  715.  
  716. The second four characters determine for each handler:
  717.  
  718.     AEVT    - Apple Event Handler Event Class.
  719.     CSPT    - Coercion input data type.
  720.     CSDS    - Coercion input data type.
  721.  
  722. The third four characters determine for each handler:
  723.  
  724.     AEVT    - Apple Event Handler Event Type.
  725.     CSPT    - Coercion output data type.
  726.     CSDS    - Coercion output data type.
  727.  
  728. The procedures are simply Pascal code resources that are declared exactly 
  729. as they are defined in IM Volume VI.
  730.  
  731.     AEVT    - Apple Event Handler:
  732.  
  733.         pascal OSErr
  734.         PROCEntry(message, reply, refcon)
  735.         AppleEvent        *message;
  736.         AppleEvent        *reply;
  737.         long            refcon;
  738.  
  739.  
  740. CSPT    - Pointer based Coercion Handler:
  741.  
  742.         pascal OSErr
  743.         PROCEntry(dataType, dataPtr, dataSize, toType, refCon, resultDesc)
  744.         DescType        dataType;
  745.         char        *dataPtr;
  746.         long        dataSize;
  747.         DescType        toType;
  748.         long        refCon;
  749.         AEDesc        *resultDesc;
  750.  
  751.     CSPT    - Pointer based Coercion Handler:
  752.  
  753.         pascal OSErr
  754.         PROCEntry(dataType, dataPtr, dataSize, toType, refCon, resultDesc)
  755.         DescType        dataType;
  756.         char        *dataPtr;
  757.         long        dataSize;
  758.         DescType        toType;
  759.         long        refCon;
  760.         AEDesc        *resultDesc;
  761.  
  762. The refCon field passed to the procedures defined for Apple Event and 
  763. Coercion contains a pointer to a parameter block that allows the procedures 
  764. to make calls back to the tcl interpreter. You obtain the pointer to this 
  765. paramater block as follows:
  766.  
  767.     XPROCPBPtr    cbpb;
  768.  
  769.         cbpb = (XPROCPBPtr) refcon;
  770.  
  771.     typedef struct {
  772.         long        version;    /* Version of the Cmd interface. */
  773.         Tcl_Interp    *interp;    /* Interpreter calling this XTCL. */
  774.         int        (*eval)();    /* Callback procedure (C) for tcl
  775.                            script evaluation */
  776.         DescType    reserved1;    /* reserved */
  777.         DescType    reserved2;    /* reserved */
  778.         long        reserved3;    /* reserved */
  779.         } XPROCParmBlk, *XPROCPBPtr;
  780.  
  781. The version field is passed in to indicate to the command what level of 
  782. functionality the tcl callback function supports, as well as indicate the 
  783. version of the parameter block data structure. The current version number 
  784. of defined by XPROC_CB_VERSION in the header file XTCL.h and is currently 
  785. 0x00010001.
  786.  
  787. The interp field is a tcl interpreter pointer to the interpreter that called the 
  788. external command. 
  789.  
  790. The eval field is a C procedure pointer to the callback routine to evaluate a 
  791. tcl statement. It is equivalent to using the eval tcl command. The callback is 
  792. used as follows:
  793.  
  794. result = (* xpb->eval)(xpb, sHandle, rHandle, stdoutHandle);
  795. Where:
  796. xpb is the parameter block pointer passed to the external command.
  797. sHandle is a handle containing a null terminated string to be evaluated by the tcl 
  798. interpreter.
  799. rHandle is a handle for the result of the command. It may be zero length, but if it is 
  800. not the results will be placed after the data already in the handle (as determined by 
  801. GetHandleSize). The result will not be null terminated, thus, GetHandleSize must 
  802. be used to determine the length of the result.
  803. stdoutHandle is a handle for the standard output of the command. This is the 
  804. output generated by the print command and error reporting. It may be zero length, 
  805. but if it is not the results will be placed after the data already in the handle (as 
  806. determined by GetHandleSize). The results will not be null terminated, thus, 
  807. GetHandleSize must be used to determine the length of the result. This field may be 
  808. NULL.
  809.  
  810. The reserved1 field is reserved. 
  811.  
  812. The reserved2 field is reserved. 
  813.  
  814. The reserved3 field is reserved. 
  815.  
  816.